package com.example.demo.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.example.demo.domain.RepairProcess;
import com.example.demo.repository.RepairProcessRepository;
import com.example.demo.service.RepairProcessService;

/**
 * @author w
 */
@Service
public class RepairProcessImpl implements RepairProcessService {
    @Resource
    RepairProcessRepository repairProcessRepository;

    @Override
    public List<RepairProcess> getAll(){
        return repairProcessRepository.findAll();
    }    

    @Override
    public List<RepairProcess> getTrainId(String trainId){
        return repairProcessRepository.findByTrainId(trainId);
    }

    @Override
    public List<RepairProcess> getYear(String year){
        return repairProcessRepository.findByYear(year);
    }

    @Override
    public RepairProcess add(RepairProcess repairProcess) {
        return repairProcessRepository.save(repairProcess);
    }

    @Override
    public RepairProcess update(Integer id,RepairProcess repairProcess) {
    	return repairProcessRepository.save(repairProcess);
    }

    @Override
    public String destory(String trainId){
        try {
            repairProcessRepository.deleteByTrainId(trainId);
            }catch(Exception e) {
        return e.getMessage();
    }
    return "true";
  }
}